<template>
  <div>
    <page-main>
      <el-table
        :data="tableData"
        style="width: 100%;"
        v-loading="tableDataLoading"
      >
        <el-table-column prop="id" width="30"></el-table-column>
        <el-table-column width="140">
          <template #default="scope">
            <el-image
              :src="scope.row.image"
              style="width: 110px; height: 80px;"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column>
          <template #default="scope">
            <div style="font-size: 16px; font-weight: bold;">
              {{ scope.row.title }}
            </div>
            <div style="color: gray; font-size: 14px;">
              <div>{{ scope.row.summary }}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column>
          <template #default="scope">
            <div class="tableColumnLastItem">
              <div>点击量：{{ scope.row.click_number }}</div>
              <div>发布时间：{{ $getDateTime(scope.row.add_time) }}</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @current-change="handleCurrentChange"
          v-model:currentPage="tableDataInfo.page"
          :page-count="tableDataInfo.total_page"
          :total="tableDataInfo.total"
          layout="total,prev, pager, next, jumper"
          background
        >
        </el-pagination>
      </div>
    </page-main>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      tableDataLoading: false,
      tableDataInfo: "",
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData(page) {
      this.tableDataLoading = true;
      let pageNum = 1;
      if (page) {
        pageNum = page;
      }
      let params = {
        page: pageNum,
        rows: 13,
      };
      this.$api
        .post("/unit/News/lists", params)
        .then((res) => {
          this.tableData = res.data.lists;
          this.tableDataInfo = res.data;
        })
        .finally(() => {
          this.tableDataLoading = false;
        });
    },
  },
};
</script>

<style>
.block {
    display: flex;
    justify-content: center;
}
.tableColumnLastItem {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}
</style>
